<?php
namespace app\admin\middleware;
class Cors
{
    public function handle($request, \Closure $next)
    {
        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
        // 如果是OPTIONS请求，则直接返回200
        if ($request->method(true) === 'OPTIONS') {
            exit;
        }
        return $next($request);
    }
}